package com.ssy.lingxi.marketing.serviceimpl.component.coupon;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.ssy.lingxi.common.constant.marketing.BelongTypeEnum;
import com.ssy.lingxi.common.constant.marketing.MerchantCouponTypeEnum;
import com.ssy.lingxi.common.constant.marketing.PlatformCouponTypeEnum;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.marketing.entity.coupon.*;
import com.ssy.lingxi.marketing.model.constant.CommonBooleanEnum;
import com.ssy.lingxi.marketing.model.constant.MerchantCouponDetailStatusEnum;
import com.ssy.lingxi.marketing.model.constant.PlatformCouponDetailStatusEnum;
import com.ssy.lingxi.marketing.model.vo.coupon.request.MobileGoodsCartRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.response.MobileCouponDetailCanUseResponse;
import com.ssy.lingxi.marketing.repository.CouponGoodsRepository;
import com.ssy.lingxi.marketing.serviceimpl.component.activity.ActivityCheckRuleComponent;
import com.ssy.lingxi.marketing.serviceimpl.component.activity.ActivityQueryComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 优惠券使用规则校验组件
 * @author yzc
 * @version 2.0.0
 * @date 2021/11/16
 */
@Slf4j
@Component
public class CouponUseCheckRuleComponent {

    @Resource
    private JPAQueryFactory queryFactory;
    @Resource
    private CouponGoodsRepository couponGoodsRepository;
    @Resource
    private ActivityQueryComponent activityQueryComponent;
    @Resource
    private ActivityCheckRuleComponent activityCheckRuleComponent;

    //=========================平台=========================

    /**
     * 已领取的平台优惠券
     */
    public List<PlatformCouponDetailDO> pfReceiveCompleteCouponDetailList(UserLoginCacheDTO loginUser,Integer environment, Long shopId, Long memberId, Long roleId) {
        return this.basePlatformCouponDetailList(loginUser,environment, shopId, null, null, memberId, roleId);
    }

    /**
     * 已领取的平台优惠券(根据状态查询)
     */
    public List<PlatformCouponDetailDO> pfReceiveCompleteByStatusCouponDetailList(UserLoginCacheDTO loginUser,Integer environment, Long shopId, Integer status, Long memberId, Long roleId) {
        return this.basePlatformCouponDetailList(loginUser, null,shopId, status, null, memberId, roleId);
    }

    /**
     * 订单可用的平台优惠券
     */
    public List<MobileCouponDetailCanUseResponse> pfOrderCanUseCouponDetailList(UserLoginCacheDTO loginUser, Long shopId, Long currentTimeMillis, BigDecimal orderAmount, List<MobileGoodsCartRequest.StoreGoods> storeGoodsList) {
        List<PlatformCouponDetailDO> platformCouponDetailDOList = this.basePlatformCouponDetailList(loginUser,null, shopId, PlatformCouponDetailStatusEnum.RECEIVE.getCode(), currentTimeMillis, null, null);
        // 订单中的商品skuId
        List<Long> skuIdList = storeGoodsList.stream().flatMap(storeGoods -> storeGoods.getSkuIdList().stream()).collect(Collectors.toList());


        // 订单满足金额才能用
        List<PlatformCouponDetailDO> filterRuleCouponDetailDOList = platformCouponDetailDOList.stream().filter(e -> e.getCoupon().getUseConditionMoney().compareTo(orderAmount) <= 0).collect(Collectors.toList());

        // 适用订单商品的优惠券
        return this.matchGoodsPlatformCoupon(filterRuleCouponDetailDOList, skuIdList);
    }

    private List<PlatformCouponDetailDO> basePlatformCouponDetailList(UserLoginCacheDTO loginUser,Integer environment, Long shopId, Integer status, Long currentTimeMillis, Long memberId, Long roleId) {
        QCouponShopDO couponShopDO = QCouponShopDO.couponShopDO;
        QPlatformCouponDetailDO platformCouponDetailDO = QPlatformCouponDetailDO.platformCouponDetailDO;

        BooleanBuilder pfPredicates = new BooleanBuilder();
        // 当前会员
        pfPredicates.and(platformCouponDetailDO.subMemberId.eq(loginUser.getMemberId()));
        pfPredicates.and(platformCouponDetailDO.subRoleId.eq(loginUser.getMemberRoleId()));
        // 当前商城是否适用
        if(shopId!=null) {
            pfPredicates.and(couponShopDO.shopId.eq(shopId));
        }
        if(environment!=null){
            pfPredicates.and(couponShopDO.environment.eq(environment));
        }
        // 状态
        if (Objects.nonNull(status)) {
            pfPredicates.and(platformCouponDetailDO.status.eq(status));
        }

        // 有效时间
        if (Objects.nonNull(currentTimeMillis)) {
            pfPredicates.and(platformCouponDetailDO.validTimeStart.loe(currentTimeMillis));
            pfPredicates.and(platformCouponDetailDO.validTimeEnd.goe(currentTimeMillis));
        }

        // 根据店铺筛选
        if (Objects.nonNull(memberId) && Objects.nonNull(roleId)) {
            pfPredicates.and(platformCouponDetailDO.memberId.eq(memberId));
            pfPredicates.and(platformCouponDetailDO.roleId.eq(roleId));
        }

        // 平台优惠券
        List<PlatformCouponDetailDO> platformCouponDetailDOList = queryFactory.select(platformCouponDetailDO)
                .from(platformCouponDetailDO)
                .leftJoin(couponShopDO).on(platformCouponDetailDO.coupon.id.eq(couponShopDO.couponId).and(couponShopDO.belongType.eq(BelongTypeEnum.PLATFORM.getCode())))
                .where(pfPredicates)
                .groupBy(platformCouponDetailDO.id)
                .fetch();

        return platformCouponDetailDOList;
    }


    //=========================商家=========================

    /**
     * 已领取的商家优惠券
     */
    public List<MerchantCouponDetailDO> mcReceiveCompleteCouponDetailList(UserLoginCacheDTO loginUser,Integer environment, Long shopId, Long memberId, Long roleId) {
        return this.baseMerchantCouponDetailList(loginUser,environment, shopId, null, null, memberId, roleId);
    }

    /**
     * 已领取的商家优惠券(根据状态查询)
     */
    public List<MerchantCouponDetailDO> mcReceiveCompleteByStatusCouponDetailList(UserLoginCacheDTO loginUser,Integer environment, Long shopId, Integer status, Long memberId, Long roleId) {
        return this.baseMerchantCouponDetailList(loginUser, environment,shopId, status, null, memberId, roleId);

    }

    /**
     * 订单可用的商家优惠券
     */
    public List<MobileCouponDetailCanUseResponse> mcOrderCanUseCouponDetailList(UserLoginCacheDTO loginUser, Long shopId, Long currentTimeMillis, BigDecimal orderAmount, List<MobileGoodsCartRequest.StoreGoods> storeGoodsList) {
        List<MerchantCouponDetailDO> merchantCouponDetailDOList = this.baseMerchantCouponDetailList(loginUser,null, shopId, MerchantCouponDetailStatusEnum.RECEIVE.getCode(), currentTimeMillis, null, null);

        // 订单中的商品skuId
        List<Long> skuIdList = storeGoodsList.stream().flatMap(storeGoods -> storeGoods.getSkuIdList().stream()).collect(Collectors.toList());

        // 过滤出符合该订单的优惠券
        List<MerchantCouponDetailDO> filterRuleCouponDetailDOList = new ArrayList<>();
        for (MerchantCouponDetailDO merchantCouponDetailDO : merchantCouponDetailDOList) {
            // 是否满足订单满额使用
            if (merchantCouponDetailDO.getCoupon().getUseConditionMoney().compareTo(orderAmount) > 0) {
                continue;
            }

            // 判断商家优惠券是否可用于该订单
            if (storeGoodsList.stream().noneMatch(storeGoods -> merchantCouponDetailDO.getMemberId().equals(storeGoods.getMemberId()) && merchantCouponDetailDO.getRoleId().equals(storeGoods.getRoleId()))) {
                continue;
            }

            filterRuleCouponDetailDOList.add(merchantCouponDetailDO);
        }

        return this.matchGoodsMerchantCoupon(filterRuleCouponDetailDOList, skuIdList);
    }

    private List<MerchantCouponDetailDO> baseMerchantCouponDetailList(UserLoginCacheDTO loginUser,Integer environment, Long shopId, Integer status, Long currentTimeMillis, Long memberId, Long roleId) {
        QCouponShopDO couponShopDO = QCouponShopDO.couponShopDO;
        QMerchantCouponDetailDO merchantCouponDetailDO = QMerchantCouponDetailDO.merchantCouponDetailDO;

        // 商家优惠券
        BooleanBuilder mcPredicates = new BooleanBuilder();
        // 当前会员
        mcPredicates.and(merchantCouponDetailDO.subMemberId.eq(loginUser.getMemberId()));
        mcPredicates.and(merchantCouponDetailDO.subRoleId.eq(loginUser.getMemberRoleId()));
        // 当前商城是否适用
        if(shopId!=null){
            mcPredicates.and(couponShopDO.shopId.eq(shopId));
        }
        // 当前商城是否适用
        if(environment!=null){
            mcPredicates.and(couponShopDO.environment.eq(environment));
        }
        // 状态
        if (Objects.nonNull(status)) {
            mcPredicates.and(merchantCouponDetailDO.status.eq(status));
        }

        // 有效时间
        if (Objects.nonNull(currentTimeMillis)) {
            mcPredicates.and(merchantCouponDetailDO.validTimeStart.loe(currentTimeMillis));
            mcPredicates.and(merchantCouponDetailDO.validTimeEnd.goe(currentTimeMillis));
        }

        // 根据店铺筛选
        if (Objects.nonNull(memberId) && Objects.nonNull(roleId)) {
            mcPredicates.and(merchantCouponDetailDO.memberId.eq(memberId));
            mcPredicates.and(merchantCouponDetailDO.roleId.eq(roleId));
        }

        // 商家优惠券
        List<MerchantCouponDetailDO> merchantCouponDetailDOList = queryFactory.select(merchantCouponDetailDO)
                .from(merchantCouponDetailDO)
                .leftJoin(couponShopDO).on(merchantCouponDetailDO.coupon.id.eq(couponShopDO.couponId).and(couponShopDO.belongType.eq(BelongTypeEnum.MERCHANT.getCode())))
                .where(mcPredicates)
                .groupBy(merchantCouponDetailDO.id)
                .fetch();

        return merchantCouponDetailDOList;
    }

    /**
     * 匹配商品(平台优惠券)
     * @param platformCouponDetailDOList 平台优惠券
     * @param skuIdList 订单中的商品skuId
     * @return 返回结果
     */
    public List<MobileCouponDetailCanUseResponse> matchGoodsPlatformCoupon(List<PlatformCouponDetailDO> platformCouponDetailDOList, List<Long> skuIdList) {
        if (CollectionUtils.isEmpty(skuIdList)) {
            return new ArrayList<>();
        }

        // 0元抵扣券
        List<PlatformCouponDetailDO> goodsCouponDetailList = new ArrayList<>();
        // 平台通用优惠券
        List<PlatformCouponDetailDO> commonCouponDetailList = new ArrayList<>();
        // 分类
        for (PlatformCouponDetailDO platformCouponDetailDO : platformCouponDetailDOList) {
            PlatformCouponDO coupon = platformCouponDetailDO.getCoupon();
            if (PlatformCouponTypeEnum.ZERO_DISCOUNT.getCode().equals(coupon.getType())) {
                goodsCouponDetailList.add(platformCouponDetailDO);
            } else if (PlatformCouponTypeEnum.COMMON.getCode().equals(coupon.getType())) {
                commonCouponDetailList.add(platformCouponDetailDO);
            }
        }

        // 返回结果
        List<MobileCouponDetailCanUseResponse> resultList = new ArrayList<>();
        if (skuIdList.size() == 1) {
            // 订单中只有一个sku商品, 所有优惠券都可用

            // 0元抵扣券处理
            List<MobileCouponDetailCanUseResponse> goodsCouponResponseList = handPfGoodsCoupon(goodsCouponDetailList, skuIdList);
            // 通用优惠券处理
            List<MobileCouponDetailCanUseResponse> commonCouponResponseList = handPfCommonCoupon(commonCouponDetailList);

            resultList.addAll(goodsCouponResponseList);
            resultList.addAll(commonCouponResponseList);

        } else {
            // 订单中商品大于1个, 只能用平台通用优惠券, 不可用0元抵扣券

            // 通用优惠券处理
            List<MobileCouponDetailCanUseResponse> commonCouponResponseList = handPfCommonCoupon(commonCouponDetailList);
            resultList.addAll(commonCouponResponseList);
        }

        return resultList;
    }

    /**
     * 处理平台通用优惠券
     * @param commonCouponDetailList 平台通用优惠券
     * @return 返回结果
     */
    private List<MobileCouponDetailCanUseResponse> handPfCommonCoupon(List<PlatformCouponDetailDO> commonCouponDetailList) {
        if (CollectionUtils.isEmpty(commonCouponDetailList)) {
            return new ArrayList<>();
        }

        List<MobileCouponDetailCanUseResponse> commonCouponResponseList = new ArrayList<>();
        for (PlatformCouponDetailDO platformCouponDetailDO : commonCouponDetailList) {
            MobileCouponDetailCanUseResponse response = new MobileCouponDetailCanUseResponse();
            response.setId(platformCouponDetailDO.getId());
            response.setCouponId(platformCouponDetailDO.getCoupon().getId());
            response.setCrateTime(platformCouponDetailDO.getCreateTime());
            response.setBelongType(BelongTypeEnum.PLATFORM.getCode());
            response.setName(platformCouponDetailDO.getCoupon().getName());
            response.setType(platformCouponDetailDO.getCoupon().getType());
            response.setTypeName(MerchantCouponTypeEnum.getCodeMessage(platformCouponDetailDO.getCoupon().getType()));
            response.setDenomination(platformCouponDetailDO.getCoupon().getDenomination());
            response.setUseConditionMoney(platformCouponDetailDO.getCoupon().getUseConditionMoney());
            response.setValidTimeStart(platformCouponDetailDO.getValidTimeStart());
            response.setValidTimeEnd(platformCouponDetailDO.getValidTimeEnd());
            response.setCrateTime(platformCouponDetailDO.getCreateTime());
            response.setSelect(CommonBooleanEnum.NO.getCode());
            response.setMemberId(platformCouponDetailDO.getMemberId());
            response.setRoleId(platformCouponDetailDO.getRoleId());
            response.setSuitableSkuIdList(Collections.emptyList());

            commonCouponResponseList.add(response);
        }

        return commonCouponResponseList;
    }

    /**
     * 处理平台0元抵扣券
     * @param goodsCouponDetailList 平台0元抵扣券
     * @return 返回结果
     */
    private List<MobileCouponDetailCanUseResponse> handPfGoodsCoupon(List<PlatformCouponDetailDO> goodsCouponDetailList, List<Long> skuIdList) {
        if (CollectionUtils.isEmpty(goodsCouponDetailList)) {
            return new ArrayList<>();
        }

        // 优惠券ids
        List<Long> couponIdList = goodsCouponDetailList.stream()
                .map(detail -> detail.getCoupon().getId())
                .collect(Collectors.toList());


        // 优惠券适用的商品
        List<CouponGoodsDO> platformCouponGoodsList = couponGoodsRepository.findAllByBelongTypeAndCouponIdIn(BelongTypeEnum.PLATFORM.getCode(), couponIdList);

        // couponId - skuIdList
        Map<Long, List<Long>> couponSkuMap = platformCouponGoodsList.stream().collect(Collectors.groupingBy(CouponGoodsDO::getCouponId, Collectors.mapping(CouponGoodsDO::getSkuId, Collectors.toList())));

        List<MobileCouponDetailCanUseResponse> goodsCouponResponseList = new ArrayList<>();
        for (PlatformCouponDetailDO platformCouponDetailDO : goodsCouponDetailList) {
            List<Long> suitableSkuIds = couponSkuMap.get(platformCouponDetailDO.getCoupon().getId());
            if (CollectionUtils.isEmpty(suitableSkuIds)) {
                continue;
            }

            // 优惠券是否适用
            if (suitableSkuIds.stream().noneMatch(skuIdList::contains)) {
                continue;
            }

            MobileCouponDetailCanUseResponse response = new MobileCouponDetailCanUseResponse();
            response.setId(platformCouponDetailDO.getId());
            response.setCouponId(platformCouponDetailDO.getCoupon().getId());
            response.setCrateTime(platformCouponDetailDO.getCreateTime());
            response.setBelongType(BelongTypeEnum.PLATFORM.getCode());
            response.setName(platformCouponDetailDO.getCoupon().getName());
            response.setType(platformCouponDetailDO.getCoupon().getType());
            response.setTypeName(MerchantCouponTypeEnum.getCodeMessage(platformCouponDetailDO.getCoupon().getType()));
            response.setDenomination(platformCouponDetailDO.getCoupon().getDenomination());
            response.setUseConditionMoney(platformCouponDetailDO.getCoupon().getUseConditionMoney());
            response.setValidTimeStart(platformCouponDetailDO.getValidTimeStart());
            response.setValidTimeEnd(platformCouponDetailDO.getValidTimeEnd());
            response.setCrateTime(platformCouponDetailDO.getCreateTime());
            response.setSelect(CommonBooleanEnum.NO.getCode());
            response.setMemberId(platformCouponDetailDO.getMemberId());
            response.setRoleId(platformCouponDetailDO.getRoleId());
            response.setSuitableSkuIdList(suitableSkuIds);

            goodsCouponResponseList.add(response);
        }

        return goodsCouponResponseList;
    }

    /**
     * 匹配商品(商家优惠券)
     * @param merchantCouponDetailDOList 商家优惠券
     * @param skuIdList 订单中的商品skuId
     * @return 返回结果
     */
    public List<MobileCouponDetailCanUseResponse> matchGoodsMerchantCoupon(List<MerchantCouponDetailDO> merchantCouponDetailDOList, List<Long> skuIdList) {
        if (CollectionUtils.isEmpty(skuIdList)) {
            return new ArrayList<>();
        }

        // 0元抵扣券
        List<MerchantCouponDetailDO> zeroCouponDetailList = new ArrayList<>();
        // 商品优惠券
        List<MerchantCouponDetailDO> goodsCouponDetailList = new ArrayList<>();
        // 商家通用优惠券
        List<MerchantCouponDetailDO> commonCouponDetailList = new ArrayList<>();
        // 分类
        for (MerchantCouponDetailDO merchantCouponDetailDO : merchantCouponDetailDOList) {
            MerchantCouponDO coupon = merchantCouponDetailDO.getCoupon();
            if (MerchantCouponTypeEnum.ZERO_DISCOUNT.getCode().equals(coupon.getType())) {
                zeroCouponDetailList.add(merchantCouponDetailDO);
            } else if (MerchantCouponTypeEnum.COMMODITY.getCode().equals(coupon.getType())) {
                goodsCouponDetailList.add(merchantCouponDetailDO);
            } else if (MerchantCouponTypeEnum.COMMON.getCode().equals(coupon.getType())) {
                commonCouponDetailList.add(merchantCouponDetailDO);
            }
        }

        // 返回结果
        List<MobileCouponDetailCanUseResponse> resultList = new ArrayList<>();
        if (skuIdList.size() == 1) {
            // 0元抵扣券, 商品优惠券处理
            goodsCouponDetailList.addAll(zeroCouponDetailList);
            List<MobileCouponDetailCanUseResponse> goodsCouponResponseList = handleMcGoodsCoupon(goodsCouponDetailList, skuIdList);
            // 通用优惠券处理
            List<MobileCouponDetailCanUseResponse> commonCouponResponseList = handleMcCommonCoupon(commonCouponDetailList);
            resultList.addAll(goodsCouponResponseList);
            resultList.addAll(commonCouponResponseList);
        } else {
            // 商品优惠券处理
            List<MobileCouponDetailCanUseResponse> goodsCouponResponseList = handleMcGoodsCoupon(goodsCouponDetailList, skuIdList);
            // 通用优惠券处理
            List<MobileCouponDetailCanUseResponse> commonCouponResponseList = handleMcCommonCoupon(commonCouponDetailList);
            resultList.addAll(goodsCouponResponseList);
            resultList.addAll(commonCouponResponseList);
        }

        return resultList;
    }

    /**
     * 处理商家通用优惠券
     * @param commonCouponDetailList 商家通用优惠券
     * @return 返回结果
     */
    private List<MobileCouponDetailCanUseResponse> handleMcCommonCoupon(List<MerchantCouponDetailDO> commonCouponDetailList) {
        List<MobileCouponDetailCanUseResponse> commonCouponResponseList = new ArrayList<>();
        for (MerchantCouponDetailDO merchantCouponDetailDO : commonCouponDetailList) {
            MobileCouponDetailCanUseResponse response = new MobileCouponDetailCanUseResponse();
            response.setId(merchantCouponDetailDO.getId());
            response.setCrateTime(merchantCouponDetailDO.getCreateTime());
            response.setCouponId(merchantCouponDetailDO.getCoupon().getId());
            response.setBelongType(BelongTypeEnum.MERCHANT.getCode());
            response.setName(merchantCouponDetailDO.getCoupon().getName());
            response.setType(merchantCouponDetailDO.getCoupon().getType());
            response.setTypeName(MerchantCouponTypeEnum.getCodeMessage(merchantCouponDetailDO.getCoupon().getType()));
            response.setDenomination(merchantCouponDetailDO.getCoupon().getDenomination());
            response.setUseConditionMoney(merchantCouponDetailDO.getCoupon().getUseConditionMoney());
            response.setValidTimeStart(merchantCouponDetailDO.getValidTimeStart());
            response.setValidTimeEnd(merchantCouponDetailDO.getValidTimeEnd());
            response.setCrateTime(merchantCouponDetailDO.getCreateTime());
            response.setSelect(CommonBooleanEnum.NO.getCode());
            response.setMemberId(merchantCouponDetailDO.getMemberId());
            response.setRoleId(merchantCouponDetailDO.getRoleId());
            response.setSuitableSkuIdList(Collections.emptyList());

            commonCouponResponseList.add(response);
        }

        return commonCouponResponseList;
    }

    /**
     * 处理商家0元抵扣券,商品优惠券
     * @param goodsCouponDetailList 商家0元抵扣券,商品优惠券
     * @return 返回结果
     */
    private List<MobileCouponDetailCanUseResponse> handleMcGoodsCoupon(List<MerchantCouponDetailDO> goodsCouponDetailList, List<Long> skuIdList) {
        List<MobileCouponDetailCanUseResponse> goodsCouponResponseList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(goodsCouponDetailList)) {
            // 优惠券ids
            List<Long> couponIdList = goodsCouponDetailList.stream()
                    .map(detail -> detail.getCoupon().getId())
                    .collect(Collectors.toList());

            // 优惠券适用的商品
            List<CouponGoodsDO> merchantCouponGoodsList = couponGoodsRepository.findAllByBelongTypeAndCouponIdIn(BelongTypeEnum.MERCHANT.getCode(), couponIdList);

            // couponId - skuIdList
            Map<Long, List<Long>> couponSkuMap = merchantCouponGoodsList.stream().collect(Collectors.groupingBy(CouponGoodsDO::getCouponId, Collectors.mapping(CouponGoodsDO::getSkuId, Collectors.toList())));

            for (MerchantCouponDetailDO merchantCouponDetailDO : goodsCouponDetailList) {
                List<Long> suitableSkuIds = couponSkuMap.get(merchantCouponDetailDO.getCoupon().getId());
                if (CollectionUtils.isEmpty(suitableSkuIds)) {
                    continue;
                }

                // 优惠券是否适用
                if (suitableSkuIds.stream().noneMatch(skuIdList::contains)) {
                    continue;
                }

                MobileCouponDetailCanUseResponse response = new MobileCouponDetailCanUseResponse();
                response.setId(merchantCouponDetailDO.getId());
                response.setCrateTime(merchantCouponDetailDO.getCreateTime());
                response.setCouponId(merchantCouponDetailDO.getCoupon().getId());
                response.setBelongType(BelongTypeEnum.MERCHANT.getCode());
                response.setName(merchantCouponDetailDO.getCoupon().getName());
                response.setType(merchantCouponDetailDO.getCoupon().getType());
                response.setTypeName(MerchantCouponTypeEnum.getCodeMessage(merchantCouponDetailDO.getCoupon().getType()));
                response.setDenomination(merchantCouponDetailDO.getCoupon().getDenomination());
                response.setUseConditionMoney(merchantCouponDetailDO.getCoupon().getUseConditionMoney());
                response.setValidTimeStart(merchantCouponDetailDO.getValidTimeStart());
                response.setValidTimeEnd(merchantCouponDetailDO.getValidTimeEnd());
                response.setCrateTime(merchantCouponDetailDO.getCreateTime());
                response.setSelect(CommonBooleanEnum.NO.getCode());
                response.setMemberId(merchantCouponDetailDO.getMemberId());
                response.setRoleId(merchantCouponDetailDO.getRoleId());
                response.setSuitableSkuIdList(suitableSkuIds);

                goodsCouponResponseList.add(response);
            }
        }

        return goodsCouponResponseList;
    }
}
